package com.codejam2012.qualification;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class C {

	public static int nTest;
	public static int A, B;
	public static int nDigits;
	public static int count;
	public static int[] ten_pow = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(new File("input.txt"));
		FileWriter writer = new FileWriter(new File("output.txt"));
		
		nTest = scanner.nextInt();
		
		for (int i=1;i<=nTest;++i) {
			int[] arr = new int[2000001];
			count = 0;
			A = scanner.nextInt();
			B = scanner.nextInt();
			
			int tmp = A;
			nDigits = 0;
			while (tmp > 0) {
				tmp = tmp / 10;
				nDigits++;
			}
			
			for (int num = A; num <= B; ++num) {
				for (int j=1;j<nDigits;++j) {
					int k = nDigits - j;
					int head = num / ten_pow[j];
					int tail = num % ten_pow[j];
					tmp = tail * ten_pow[k] + head;
					if (tmp > num && tmp <= B) {
						if (arr[tmp] != num) {
							arr[tmp] = num;
							count++;
						}
					}
				}
			}
			writer.write("Case #" + i + ": " + count);
			if (i < nTest) {
				writer.write("\n");
			}
			writer.flush();
		}
		writer.close();
	}
}
